<template>
  <div>
    <!--<Button type="primary" @click="exportDataInventory(checkOrderNo)">
      <Icon type="ios-download-outline"></Icon>
      导出原始数据
    </Button>-->
    <tablePage ref="containerTab" :api="getRailwayEmptyOrderList" :param="tabParam" >
      <template slot-scope="props">
        <Table :columns="containerColumn" :data="props.data"></Table>
      </template>
    </tablePage>
    <xlinkModal v-model="operatModal.viewDetailShow" title="查看详情" width="960">
      <viewDetailMainOrderList v-if="operatModal.viewDetailShow" :currentMainOrder="mainOrderCurrentRow"></viewDetailMainOrderList>
    </xlinkModal>
  </div>
</template>
<script>
  import tablePage from '@components/table/tablePage.vue'
  import xlinkModal from '@components/modal/xlinkModal'
  import viewDetailMainOrderList from './components/viewDetailMainOrderList'
  import { exportUtil } from '@/vendor/exportInvoke'
  import {getRailwayEmptyOrderList, getRailwayEmptyOrderListByOrderNo} from '@api/backEnd/station'
  import moment from 'moment'

  export default {
    name: 'stationContainerDetail',
    data () {
      let tabParam = {}
      let operatModal = { viewDetailShow: false }
      let mainOrderCurrentRow = {}
      let checkOrderNo = []
      let containerColumn = [
        {
          title: '单号',
          width: 300,
          key: 'order_no',
          align: 'center'
        },
        {
          title: '时间',
          ellipsis: true,
          align: 'center',
          key: 'create_time',
          render: (h, params) => {
            let thisdata = params.row.create_time
            thisdata = thisdata ? moment(thisdata).format('YYYY-MM-DD HH:mm') : ''
            return (<span>{thisdata}</span>)
          }
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          width: 250,
          render: (h, params) => {
            let viewDetailBtn = (<i-button type="primary" size="small" style="margin-right: 5px;" onClick={() => this.viewDetailAction(params.row)}>查看详情</i-button>)
            let exportBtn = (<i-button type="success" size="small" style="margin-right: 5px;" onClick={() => this.exportDataInventory(params.row.order_no)}>导出数据</i-button>)
            let btnArray = []
            btnArray.push(viewDetailBtn)
            btnArray.push(exportBtn)
            return (btnArray)
          }
        }
      ]
      let datas = { tabParam, containerColumn, getRailwayEmptyOrderList, operatModal, mainOrderCurrentRow, checkOrderNo }
      return datas
    },
    props: {
    },
    watch: {},
    methods: {
      viewDetailAction (row) {
        this.mainOrderCurrentRow = row
        this.operatModal.viewDetailShow = true
      },
      subOrderCheck (selection) {
        this.checkOrderNo = []
        selection.forEach((item) => {
          this.checkOrderNo.push(item.order_no)
        })
      },
      exportDataInventory (item) {
        /* if (item.length<=0){
          this.$Message.error('请勾选单号')
          return false
        } */
        let param = {
          orderNo: item
        }
        getRailwayEmptyOrderListByOrderNo(param).then(res => {
          if (res.data.isSuccess === 1) {
            let resDate = res.data.data
            let result = this.fasetJson(resDate)
            exportUtil.export2Excel('空箱回送', result.columns, result.data)
          }
        })
      },
      fasetJson (tabData) {
        let result = {
          columns: [
            { title: '车序', key: 'trainSort' },
            { title: '单号', key: 'orderNo' },
            { title: '车号', key: 'trainNumber' },
            { title: '箱号1', key: 'containerNo1' },
            { title: '箱号2', key: 'containerNo2' },
            { title: '创建时间', key: 'createTime' },
            { title: '绑箱时间', key: 'bindTime' }
          ],
          data: []
        }
        let indexCount = 0
        tabData.forEach((item) => {
          let dataItem = {
            trainSort: item.trainSort,
            orderNo: item.orderNo,
            trainNumber: item.trainNumber,
            containerNo1: item.containerNo1,
            containerNo2: item.containerNo2,
            createTime: item.createTime ? moment(item.createTime).format('YYYY-MM-DD HH:mm') : '',
            bindTime: item.bindTime ? moment(item.bindTime).format('YYYY-MM-DD HH:mm') : ''
          }
          result.data.push(dataItem)
          indexCount++
        })
        console.log(indexCount)
        return result
      }
    },
    mounted () {
    },
    components: { tablePage, xlinkModal, viewDetailMainOrderList }
  }
</script>
<style scoped>
  h2 {
    margin: 20px 0;
    font-size: 18px;
    font-weight: bold;
  }

  .lh-32 {
    line-height: 32px;
    margin-right: 5px;
  }
</style>
